#include "lomb/evaluate_average_and_variance.h"

void evalulate_average_and_variance(unsigned long n, double* data,
        double* average, double* variance)
{
    *average = 0.0;
    for (unsigned long i = 0; i < n; ++i)
    {
        *average += data[i];
    }
    *average /= n;

    *variance = 0.0;
    double ep = 0.0;
    for (unsigned long i = 0; i < n; ++i)
    {
        double s = data[i] - (*average);
        ep += s;
        *variance += s*s;
    }
    *variance = (*variance - ep * ep / n) / (n - 1);
}

